<template>
    <div class="too" @scroll="dScroll">
        <div class="ff">
            <div class="box">
                <Headers></Headers>
            </div>
    
            <Lunbo :swi="swi" class="lunbo"> </Lunbo>
            <Daohang></Daohang>
        </div>
        <List :list="list"> </List>
        <!--底部foot是否出现-->
        <div class="bot-tabbar" v-if='Tabxian'>
            <Foot></Foot>
        </div>
    
    </div>
</template>
<script>
import Headers from '../components/Headers.vue'
import Lunbo from "../components/Lunbo.vue"
import List from "../components/List.vue"

import Daohang from "../components/Daohang.vue"
import Foot from '../components/Foot.vue'
// import { Swiper } from "vux";
export default {
    components: {
        Headers,
        Lunbo,
        List,
        Daohang,
        Foot
    },
    data: function () {
        return {
            swi: [],
            list: [],
            isLoading: false,  //正在加载....
            Tabxian: false  //下面提示栏是否出现
        }
    },
    activated: function () {
        this.$el.scrollTop = this.currentOffset;
    },

    mounted: function () {
        this.requestLunbo(),
        this.requestList(),
        //  底部下面提示栏
        this.$el.onscroll = function (e) {
            //滚动偏移量
            var offset = e.target.scrollTop;
            this.currentOffset = offset;
            //元素本身高度
            // var height = e.target.clientHeight;
            //元素的内容高度
            // var contentHeight = e.target.scrollHeight;
            // 下导航栏
            if (offset > 0) {
                this.Tabxian = true;
            }
            else {
                this.Tabxian = false;
            }
        }.bind(this);

    },
    methods: {
        // 下拉加载更多
        dScroll: function (e) {
            // console.log(e.target.offsetHeight)
            // console.log(e.target.scrollHeight)
            // console.log(e.target.scrollTop)
            if (this.isLoading) {
                return
            }
            var oh = e.target.offsetHeight;
            var ch = e.target.scrollHeight;
            var os = e.target.scrollTop;
            if (os + oh + 50 > ch) {
                console.log("到底了");
                this.requestList();
            }
        },
        // 轮播图请求
        requestLunbo: function () {
            this.$http.get("dt/napi/mbanner/?", {
                params: {
                    app_code: "mdt",
                }
            })
                .then(function (res) {
                    console.dir(res.data.data.object_list)
                    this.swi = res.data.data.object_list
                }.bind(this))
        },
        // 详细列表请求
        requestList: function () {
            this.isLoading = true
            this.$http.get("dt/napi/index/hot/?", {
                params: {
                    start: this.list.length,
                    include_fields: "sender%2Calbum",
                    limit: 24,
                    _: "1497260029539",
                }
            })
                .then(function (res) {
                    this.isLoading = false
                    console.dir(res.data.data.object_list)
                    this.list = this.list.concat(res.data.data.object_list)
                }.bind(this))
        }
    },
}
</script>
<style scoped>
.too {
    /*页面滚动必须给监听的盒子元素设置高*/
    height: 100vh;
    overflow: scroll;
}

.bot-tabbar {
    position: fixed;
    bottom: 0px;
}
</style>
